package com.itheima.service.impl;

import com.itheima.dao.StudentMapper;
import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class StudentServiceImpl  implements StudentService {
    public List<Student> find() {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("MyBatisConfig.xml");
            SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);

            SqlSession sqlSession = build.openSession();

            StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
            List<Student> students = mapper.find();


            return students;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return  null;
    }
}
